package com.iring.dao.common;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;

import com.iring.domain.common.PayOrder;


/**
 * 订单信息dao
 *
 * @author wanggan
 */
public interface PayOrderDao extends JpaRepository<PayOrder, Integer> {

    List<PayOrder> findByUsernameAndPayStatusInAndOrderStatusIn(String username, List<String> stringList, List<String> orderList);

    List<PayOrder> findByPayStatusInAndOrderStatusIn(List<String> stringList, List<String> orderList);
    /**
     * 查找用户的支付状态为未支付的列表
     * @param username
     *          用户名
     * @param stringList
     *          需要查询的参数
     * @return  未完成的订单列表
     */
    List<PayOrder> findByUsernameAndPayStatusIn(String username, List<String> stringList);

    List<PayOrder> findByUsername(String username);
    /**
     * 通过订单id查找订单
     *
     * @param orderid
     *            订单id
     * @return 订单详情
     */
    PayOrder findByOrderId(String orderid);

    PayOrder findByTradeNo(String tradeNo);

    PayOrder findByUsernameAndOrderIdAndOrderStatusIn(String username, String orderid, List<String> stringList);

    PayOrder findByUsernameAndOrderIdAndPayStatusIn(String username, String orderid, List<String> stringList);

    PayOrder findDistinctByOrderId(String orderid);

    /**
     * 执行本地充值订单事务
     *
     * @param orderid
     *            支付id
     * @param opttype
     *            支付类型
     * @return 支付结果
     */
    @Procedure(procedureName = "USP_ORDER_UPDATE_PAY_PROC")
    Integer updateOrderTrans(String orderid, Integer opttype);
}
